﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.IO;
using System.Threading;
using System.Configuration;
using System.Windows.Forms;
using DrugStorehouseMIS.BLL;
using DrugStorehouseMIS.StockInAndOutManager;
using DrugStorehouseMIS.Help;
using DrugStorehouseMIS.QueryAndReport;
using DrugStorehouseMIS.SystemProtected;
using DrugStorehouseMIS.StockManager;
using Aptech.UI;

namespace DrugStorehouseMIS
{
    public partial class frmMain : Form
    {
        public static User userObject;

        public frmMain(User obj)
        {
            InitializeComponent();
            skinEngine1.SkinFile = AppDomain.CurrentDomain.BaseDirectory + @"\Skins\DiamondBlue.ssk";

            userObject = obj;
     
            #region 创建侧面菜单栏
            //sideBar1.AddGroup("系统管理");
            //sideBar1.AddGroup("客房信息管理");
            //sideBar1.AddGroup("订房信息管理");
            //sideBar1.AddGroup("结算信息管理");
            //sideBar1.AddGroup("帮助");

            //sideBar1.Groups[0].Items.Add("用户管理", 0);
            //sideBar1.Groups[0].Items.Add("密码管理", 0);
            //sideBar1.Groups[0].Items.Add("数据备份", 0);
            //sideBar1.Groups[0].Items.Add("数据恢复", 0);
            //sideBar1.Groups[0].Items.Add("退出系统", 0);

            //sideBar1.Groups[1].Items.Add("客房信息查询", 0);
            //sideBar1.Groups[1].Items.Add("客房信息修改", 0);
            //sideBar1.Groups[1].Items.Add("客房信息添加", 0);

            //sideBar1.Groups[2].Items.Add("订房信息查询", 0);
            //sideBar1.Groups[2].Items.Add("订房信息修改", 0);
            //sideBar1.Groups[2].Items.Add("订房信息添加", 0);
            //sideBar1.Groups[2].Items.Add("剩余订房信息查询", 0);

            //sideBar1.Groups[3].Items.Add("结算信息查询", 0);
            //sideBar1.Groups[3].Items.Add("结算信息修改", 0);
            //sideBar1.Groups[3].Items.Add("结算信息添加", 0);
            #endregion

        }

        private void frm_Main_Load(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            this.statusUser.Text = "当前操作员：" + userObject.UserName;
            this.statusUserType.Text = "当前用户类型：" + userObject.UserType;


            switch (userObject.UserType)
            {
                case "超级管理员":
                    break;
                case "出入库管理员":
                    tsmiDeptInfo.Enabled = false;
                    break;
                case "":
                    break;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.statusTime.Text = "当前时间：" + DateTime.Now.ToString();
        }

        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }
　　　　
        /// <summary>
        /// 查询MDI子窗体是否存在
        /// </summary>
        /// <param name="childFrmName"></param>
        /// <returns></returns>
        private bool checkChildFrmExist(string childFrmName)
        {
            foreach (Form childFrm in this.MdiChildren)
            {
                if (childFrm.Name == childFrmName) //用子窗体的Name进行判断，如果存在则将他激活
                {
                    if (childFrm.WindowState == FormWindowState.Minimized)
                        childFrm.WindowState = FormWindowState.Normal;
                    childFrm.Activate();
                    return true;
                }
            }
            return false;
        }

        #region 出入库管理

        private void tsmiDrugIn_Click(object sender, EventArgs e)
        {
            if (this.checkChildFrmExist("frmStockIn") == true)
            {
                return;
            }
            frmStockIn form = new frmStockIn();
            form.FormBorderStyle = FormBorderStyle.None;
            form.TopLevel = false;
            form.MdiParent = this;
            form.Dock = DockStyle.Fill;
            form.Show();
        }

        private void tsmiDrugOut_Click(object sender, EventArgs e)
        {
            if (this.checkChildFrmExist("frmStockOut") == true)
            {
                return;
            }
            frmStockOut form = new frmStockOut();
            form.FormBorderStyle = FormBorderStyle.None;
            form.TopLevel = false;
            form.MdiParent = this;
            form.Dock = DockStyle.Fill;
            form.Show();
        }

        #endregion


        #region 库存管理

        private void drug_count_list_ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.checkChildFrmExist("drug_count_list") == true)
            {
                return;
            }
            frmStockCountList form = new frmStockCountList();

            form.FormBorderStyle = FormBorderStyle.None;
            form.TopLevel = false;
            form.MdiParent = this;
            form.Dock = DockStyle.Fill;
            form.Show(); 
        }

        private void price_adjust_list_ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.checkChildFrmExist("price_adjust_list") == true)
            {
                return;
            }
            price_adjust_list form = new price_adjust_list();

            form.FormBorderStyle = FormBorderStyle.None;
            form.TopLevel = false;
            form.MdiParent = this;
            form.Dock = DockStyle.Fill;
            form.Show(); 
        }

        private void drug_warm_ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.checkChildFrmExist("drug_warm") == true)
            {
                return;
            }
            drug_warm form = new drug_warm();

            form.FormBorderStyle = FormBorderStyle.None;
            form.TopLevel = false;
            form.MdiParent = this;
            form.Dock = DockStyle.Fill;
            form.Show(); 
        }

        #endregion


        #region 查询与统计

        private void in_query_ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //if (this.checkChildFrmExist("in_query") == true)
            //{
            //    return;
            //}
            //in_query form = new in_query();

            //form.FormBorderStyle = FormBorderStyle.None;
            //form.TopLevel = false;
            //form.MdiParent = this;
            //form.Dock = DockStyle.Fill;
            //form.Show(); 
        }

        private void out_query_ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //if (this.checkChildFrmExist("out_query") == true)
            //{
            //    return;
            //}

            //out_query form = new out_query();
            //form.FormBorderStyle = FormBorderStyle.None;
            //form.TopLevel = false;
            //form.MdiParent = this;
            //form.Dock = DockStyle.Fill;
            //form.Show();
        }
        private void store_query_ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.checkChildFrmExist("store_query") == true)
            {
                return;
            }

            store_query form = new store_query();
            form.FormBorderStyle = FormBorderStyle.None;
            form.TopLevel = false;
            form.MdiParent = this;
            form.Dock = DockStyle.Fill;
            form.Show();
        }

       

        private void order_plan_ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.checkChildFrmExist("order_list") == true)
            {
                return;
            }

            order_list form = new order_list();
            form.FormBorderStyle = FormBorderStyle.None;
            form.TopLevel = false;
            form.MdiParent = this;
            form.Dock = DockStyle.Fill;
            form.Show();
        }


        private void tsmiDrugInfoSearch_Click(object sender, EventArgs e)
        {
            if (this.checkChildFrmExist("frmDrugInfo") == true)
            {
                return;
            }
            frmDrugInfo form = new frmDrugInfo();
            form.FormBorderStyle = FormBorderStyle.None;
            form.TopLevel = false;
            form.MdiParent = this;
            form.Dock = DockStyle.Fill;
            form.Show();
        }          

          

       

       

       

        #endregion


        #region 基本信息维护

        private void tsmiDeptInfo_Click(object sender, EventArgs e)
        {
            frmDictionary form = new frmDictionary();
            form.FormBorderStyle = FormBorderStyle.None;
            form.TopLevel = false;
            form.MdiParent = this;
            form.Dock = DockStyle.Fill;
            form.Show();

        }

        private void tsmiDrugInfo_Click(object sender, EventArgs e)
        {
            if (this.checkChildFrmExist("durg_info_manager") == true)
            {
                return;
            }
            durg_info_manager form = new durg_info_manager();
            form.FormBorderStyle = FormBorderStyle.None;
            form.TopLevel = false;
            form.MdiParent = this;
            form.Dock = DockStyle.Fill;
            form.Show();
        }
        private void menuDrug_Click(object sender, EventArgs e)
        {
            if (this.checkChildFrmExist("frmDictionary") == true)
            {
                return;
            }

            frmDictionary form = new frmDictionary();
            form.MdiParent = this;
            form.Show();
        }





        #endregion

        #region 系统维护

        private void menuDataBack_Click(object sender, EventArgs e)
        {
            //通过窗体名称查询该窗体是否已经存在，如存在则显示，否则就新创建一个
            if (this.checkChildFrmExist("frmDataBack") == true)
            {
                return;
            }

            frmDataBack form = new frmDataBack();
            form.MdiParent = this;
            form.Show();
        }

        private void menuDataReole_Click(object sender, EventArgs e)
        {
            if (this.checkChildFrmExist("frmDataReole") == true)
            {
                return;
            }

            frmDataReole form = new frmDataReole();
            form.MdiParent = this;
            form.Show();
        }


        #endregion　


        #region 工具

        private void menuCalculate_Click(object sender, EventArgs e)
        {
            Process.Start("calc");
        }

        private void menuNote_Click(object sender, EventArgs e)
        {
            Process.Start("notepad");
        }

        #endregion


        #region 窗口

        private void menuWindows_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem a = (ToolStripMenuItem)sender;

            switch (a.Text)
            {
                case "层叠(&C)":
                    this.LayoutMdi(MdiLayout.Cascade);
                    break;
                case "水平平铺(&H)":
                    this.LayoutMdi(MdiLayout.TileVertical);
                    break;
                case "垂直平铺(&V)":
                    this.LayoutMdi(MdiLayout.TileHorizontal);
                    break;
                case "图标排列(&A)":
                    this.LayoutMdi(MdiLayout.ArrangeIcons);
                    break;
            }
        }

        #endregion


        #region 帮助

        private void menuAbout_Click(object sender, EventArgs e)
        {
            if(this.checkChildFrmExist("frmAbout")==true)
            {
                return;
            }
            frmAbout form = new frmAbout();
            //form.MdiParent = this;
            form.ShowDialog();
        }

        private void tsmiSearch_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("http://www.baidu.com");
        }


        #endregion

        private void 低于下限报警ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void 高于ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        #region 工具栏

        private void tsbStockIn_Click(object sender, EventArgs e)
        {
            if (this.checkChildFrmExist("frmStockIn") == true)
            {
                return;
            }
            frmStockIn form = new frmStockIn();
            form.FormBorderStyle = FormBorderStyle.None;
            form.TopLevel = false;
            form.MdiParent = this;
            form.Dock = DockStyle.Fill;
            form.Show();
        }

        private void tsbStockOut_Click(object sender, EventArgs e)
        {
            if (this.checkChildFrmExist("frmStockOut") == true)
            {
                return;
            }
            frmStockOut form = new frmStockOut();
            form.FormBorderStyle = FormBorderStyle.None;
            form.TopLevel = false;
            form.MdiParent = this;
            form.Dock = DockStyle.Fill;
            form.Show();
        }

        private void tsbExit_Click(object sender, EventArgs e)
        {
            DialogResult dialogResult = MessageBox.Show("确定退出吗？", "退出系统", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (dialogResult == DialogResult.OK)
            {
                Application.Exit();
            }
        }

        #endregion


   
        #region 其他

        #endregion

    }
}